package com.yanqu.road.server.channelserver.manager.log.impl;

import com.yanqu.road.dao.impl.log.LogEnterNameDaoImpl;
import com.yanqu.road.entity.log.LogEnterNameActivityRank;
import com.yanqu.road.server.channelserver.manager.log.BaseChannelLog;

import java.util.ArrayList;
import java.util.List;

public class ChannelLogEnterNameLogic extends BaseChannelLog {

    private static final List<LogEnterNameActivityRank> logEnterNameActivityRankList = new ArrayList<>();


    public static void addLogEnterNameRankList(List<LogEnterNameActivityRank> logList) {
        synchronized (logEnterNameActivityRankList) {
            logEnterNameActivityRankList.addAll(logList);
        }
    }

    private static void savEnterNameRank() {
        List<LogEnterNameActivityRank> list;
        synchronized (logEnterNameActivityRankList) {
            list = new ArrayList<>(logEnterNameActivityRankList);
            logEnterNameActivityRankList.clear();
        }
        if (list.size() > 0) {
            new LogEnterNameDaoImpl().addLogEnterNameActivityRankList(list);
        }
        if (list.size() >= 1000) {
            logger.debug("addLogEnterNameRank size {}", list.size());
        }
    }

    @Override
    public void save() {
        savEnterNameRank();
    }
}
